package com.hubei.controller;

import com.hubei.pojo.User;
import com.hubei.service.UserService;
import com.hubei.service.Impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userservice;


    @RequestMapping(value = "/list.action")
    public String queryUserList(Model model,User user) {
        System.out.println(user.getUsername());
        System.out.println(user.getGender());
        List<User> list = userservice.queryUserList();
        model.addAttribute("userList", list);
        return "user_list";
    }

    @RequestMapping("/add.action")
    public String userAdd() {


        return "user_add";
    }

    @RequestMapping("/test_json.action")
    @ResponseBody
    public User testJson(User user) {
        System.out.println(user.getUsername() + "===" + user.getGender());
        user.setEmail("564654546@163.com");
        user.setUsername("李典");
        return user;
    }

}
